import { TAB_VALUES } from "./constant";

class JudgeStatus {
	//订单状态id
	ID_INFO = {
		//待发货
		waitSales: [1],
		//已发货
		sales: [2, 3],
		//退款中
		inRefunded: [11, 12, 13, -11, -12],
		//交易成功
		success: [4, 5],
		//关闭的订单
		close: [-1],
		//继续发货
		continueSend: [101]
	};

	//退款状态id
	REFUND_ID_INFO = {
		// 商家已拒绝您的请求 商家已拒绝您的请求
		merchantRefused: -2,
		// 撤销申请 撤销申请
		withdrawApplication: -1,
		// 商家审核 商家审核
		waitMerchantAudit: 1,
		//商家退款中 商家审核通过，退款中
		merchantRefundInProgress: 2,
		// 退款完成 退款完成
		refundComplete: 3
	};

	private getFlag = (data: any, ids) => ids.includes(data?.order_status);
	private getRefundFlag = (data: any, id) => id === data?.aftersale_status;

	//判断是否是待发货
	isWaitSales = (data: any) => this.getFlag(data, this.ID_INFO.waitSales) || this.isContinueSend(data);

	//判断是否是已发货
	isSales = (data: any) => this.getFlag(data, this.ID_INFO.sales);

	//判断是否交易成功
	isSalesSuccess = (data: any) => this.getFlag(data, this.ID_INFO.success);
	//交易成功待评价
	isSalesSuccessWaitComment = (data: any) => this.isSalesSuccess(data) && data.order_status === 4;
	//交易成功已评价
	isSalesSuccessCommented = (data: any) => this.isSalesSuccess(data) && data.order_status === 5;
	//判断是否是继续发货
	isContinueSend = (data: any) => this.getFlag(data, this.ID_INFO.continueSend);
	//判断是否是不分发货
	isPartialDelivery = (data: any) =>
		data?.is_all_send === 0 && data?.order_have_send_spec_ids?.length !== data?.itemsList?.length;

	//判断是否交易关闭 （-1超时交易关闭的）
	isSalesClose = (data: any) => this.getFlag(data, this.ID_INFO.close);

	//判断是否是退款中
	isInRefunded = (data: any) => this.getFlag(data, this.ID_INFO.inRefunded);
	//是否是退款中待商家审核
	isInRefundedWaitAudit = (data: any) =>
		this.isInRefunded(data) && this.getRefundFlag(data, this.REFUND_ID_INFO.waitMerchantAudit);
	//是否退款完成
	isInRefundedComplete = (data: any) => this.isInRefunded(data) && this.getRefundFlag(data, this.REFUND_ID_INFO.refundComplete);
	//判断是否是急速退款
	isQuickRefund = (data: any) => this.isInRefundedComplete(data) && data?.aftersales_info?.is_fast === 1;
	//判断是否是商家决绝退款
	isMerchantInRefundedRefuse = (data: any) =>
		this.isInRefunded(data) && this.getRefundFlag(data, this.REFUND_ID_INFO.merchantRefused);
}

export default new JudgeStatus();
